<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.48">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
span.s1 {color: #0000bf}
span.s2 {color: #007300}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1">//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://www.informatics.sussex.ac.uk/users/nc81/</p>
<p class="p2"><br></p>
<p class="p3"><b>TwoTube<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>physical modeling simulation; two tubes</b></p>
<p class="p2"><br></p>
<p class="p4"><b>TwoTube.ar(input=0, k=0.01, loss=1.0, d1length=100,d2length=100,<span class="Apple-converted-space">  </span>mul = 1.0, add = 0.0)</b></p>
<p class="p5"><br></p>
<p class="p4">Physical model; two tube sections with scattering junction inbetween; their relative areas determine k.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>input</b>- Excitation to inject into the system</p>
<p class="p4"><b>k</b>- <span class="Apple-tab-span">	</span><span class="Apple-converted-space">  </span>Scattering coefficient for junction of two tubes, usually -1&lt;=k&lt;=1</p>
<p class="p4"><b>loss</b>-<span class="Apple-converted-space">  </span>Amplitude loss factor in circulation</p>
<p class="p4"><b>d1length</b>- Length in samples of first delay line</p>
<p class="p4"><b>d2length</b>- Length in samples of second delay line (no interpolation implemented yet)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p8">{</p>
<p class="p8"><span class="s1">var</span> delay1, delay2, source;<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p1">//k from -1 to 1</p>
<p class="p7"><br></p>
<p class="p1">//in samples</p>
<p class="p8">delay1= 100;<span class="Apple-converted-space"> </span></p>
<p class="p8">delay2= 40;</p>
<p class="p7"><br></p>
<p class="p8">source= <span class="s1">WhiteNoise</span>.ar(0.5)*<span class="s1">EnvGen</span>.ar(<span class="s1">Env</span>([1,1,0],[(delay1+delay2)/<span class="s1">SampleRate</span>.ir,0.0]), Impulse.kr(MouseY.kr(1,4)));</p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">TwoTube</span>.ar(source,<span class="s1">MouseX</span>.kr(-1,1),0.99,delay1,delay2);<span class="Apple-converted-space"> </span></p>
<p class="p8">}.play</p>
<p class="p7"><br></p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p8"><span class="s1">SynthDef</span>(<span class="s2">\twotube</span>,{<span class="s1">arg</span> delay1=100, delay2=50, k=0.0, loss=0.999, dur=0.5, pan=0.0;<span class="Apple-converted-space"> </span></p>
<p class="p8"><span class="s1">var</span> source;<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p1">//k from -1 to 1</p>
<p class="p7"><br></p>
<p class="p8">source= <span class="s1">WhiteNoise</span>.ar(0.5)*<span class="s1">EnvGen</span>.ar(<span class="s1">Env</span>([1,1,0,0],[(delay1+delay2)/<span class="s1">SampleRate</span>.ir,0.0,1.0]));</p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(<span class="s1">TwoTube</span>.ar(source,k,loss,delay1,delay2)*<span class="s1">EnvGen</span>.ar(<span class="s1">Env</span>([0,1,1,0],[0.001]++((dur-0.001)*[0.4,0.6])),doneAction:2),pan));<span class="Apple-converted-space"> </span></p>
<p class="p8">}).send(s);<span class="Apple-converted-space"> </span></p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p8">t.stop;</p>
<p class="p8">t={</p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">inf</span>.do{</p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">Synth</span>(<span class="s2">\twotube</span>,[<span class="s2">\delay1</span>, rrand(1,300),<span class="s2">\delay2</span>, rrand(1,300),<span class="s2">\loss</span>, rrand(0.9,0.999),<span class="s2">\dur</span>, rrand(0.1,5.0), <span class="s2">\pan</span>, rrand(-1,1.0), <span class="s2">\k</span>, rrand(-1,1.0)]);</p>
<p class="p7"><br></p>
<p class="p8">0.5.wait;</p>
<p class="p8">};</p>
<p class="p7"><br></p>
<p class="p8">}.fork;</p>
<p class="p8">)</p>
<p class="p6"><br></p>
</body>
</html>
